#include"comm.hpp"

int main()
{
    key_t k=getkey();
    printf("kry:0x%x\n",k);

    int shmid=createShm(k); //创建
    printf("shmid:%d\n",shmid);

    sleep(5);

    char* start=(char*)attachShm(shmid);//挂接/关联
    printf("attach success, address start:%p\n",start);

    //使用
    while(true)
    {
        printf("client say:%s\n",start);

        struct shmid_ds ds;
        shmctl(shmid, IPC_STAT, &ds);
        printf("获取属性: size: %d, pid: %d, myself: %d, key: 0x%x",\
                ds.shm_segsz, ds.shm_cpid, getpid(), ds.shm_perm.__key);

        sleep(1);
    }

    //去关联
    detachShm(start);

    sleep(10);
    //删除共享内存
    delShm(shmid);//删除
    return 0;
}